//
//  SubjectMoreEditView.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/11/7.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "SubjectMoreEditView.h"

@interface SubjectMoreEditView()

@property(nonatomic,copy)MoreEditBlock zblock;

@end

@implementation SubjectMoreEditView

-(instancetype)initWithFrame:(CGRect)frame andBlock:(MoreEditBlock)block
{
    if (self=[super initWithFrame:frame]) {
        
        self=[[[NSBundle mainBundle]loadNibNamed:@"SubjectMoreEditView" owner:self options:nil]lastObject];
        
        self.frame=frame;
        
        self.BtnView.layer.cornerRadius=5.0;
        self.BtnView.layer.masksToBounds=YES;
        
        _zblock=block;
    }
    
    return self;
}


-(void)popWithSuperView:(UIView*)superView
{
    [superView addSubview:self];
    
    POPBasicAnimation *BaseA=[POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
    
    BaseA.fromValue=@(0.0);
    
    BaseA.toValue=@(0.3);
    
    BaseA.duration=0.3;
    
    [self.BagView pop_addAnimation:BaseA forKey:@"fade"];
    
    POPSpringAnimation *anSpring=[POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
    
    anSpring.fromValue=[NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2.0, -self.BtnView.height/2.0)];;
    
    anSpring.toValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2.0, self.center.y)];

    anSpring.springBounciness = 10.0f;
    
    [self.BtnView pop_addAnimation:anSpring forKey:@"position"];
    
    
}

- (IBAction)PassAction:(UIButton *)sender {
    
    _zblock(1);
    
    [self dissMiss];
    
}
- (IBAction)NotPassAction:(UIButton *)sender {
    
       _zblock(0);
    [self dissMiss];
}
- (IBAction)NotSuitAction:(UIButton *)sender {
    
       _zblock(2);
    
    [self dissMiss];
}

-(void)dissMiss
{
    
    POPBasicAnimation *BaseA=[POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
    
    BaseA.fromValue=@(0.3);
    
    BaseA.toValue=@(0.0);
    
    BaseA.duration=0.3;
    
    [self.BagView pop_addAnimation:BaseA forKey:@"fade"];
    
    POPSpringAnimation *anSpring=[POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];

     anSpring.fromValue = [NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2.0, self.center.y)];
    
    anSpring.toValue=[NSValue valueWithCGPoint:CGPointMake(SCREEN_WIDTH/2.0, -self.BtnView.height/2.0)];;
 
    anSpring.springBounciness = 10.0f;
    [self.BtnView pop_addAnimation:anSpring forKey:@"position"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self removeFromSuperview];
        
    });
    
}
- (IBAction)CloseAction:(UIButton *)sender {

    [self dissMiss];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
